package com.ellecity06.common.base

import android.app.AlertDialog
import android.content.Context
import android.content.ContextWrapper
import android.content.res.Resources


/**
 *@author joe
 *@data 2024/10/28
 *@describe
 */
class BaseAlertDialogBuilder : AlertDialog.Builder {
    constructor(context: Context) : super(adjustAutoSize(context)) {}
    constructor(context: Context, themeResId: Int) : super(adjustAutoSize(context), themeResId) {}

    companion object {
        private fun adjustAutoSize(context: Context): Context {
            return object : ContextWrapper(context) {
                private var mResources: Resources? = null

                init {
                    val oldResources: Resources = super.getResources()
                    mResources = Resources(oldResources.assets, oldResources.displayMetrics, oldResources.configuration)
                }

                override fun getResources(): Resources {
                    return mResources!!
                }
            }
        }
    }
}